home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / time / localtime.c < prev    next >
C/C++ Source or Header  |  1993-05-16  |  2KB  |  85 lines

  1. /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <ansidecl.h>
  20. #include <localeinfo.h>
  21. #include <stddef.h>
  22. #include <ctype.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <time.h>
  27.  
  28.  
  29. #ifndef    HAVE_GNU_LD
  30. #define    __tzname    tzname
  31. #define    __daylight    daylight
  32. #define    __timezone    timezone
  33. #endif
  34.  
  35. /* Return the `struct tm' representation of *TIMER in the local timezone.  */
  36. struct tm *
  37. DEFUN(localtime, (timer), CONST time_t *timer)
  38. {
  39.   extern int __use_tzfile;
  40.   extern int EXFUN(__tz_compute, (time_t timer, struct tm *tp));
  41.   extern int EXFUN(__tzfile_compute, (time_t timer,
  42.                       long int *leap_correct, int *leap_hit));
  43.   register struct tm *tp;
  44.   long int leap_correction;
  45.   int leap_extra_secs;
  46.  
  47.   if (timer == NULL)
  48.     {
  49.       errno = EINVAL;
  50.       return NULL;
  51.     }
  52.  
  53.   {
  54.     /* Make sure the database is initialized.  */
  55.     extern int __tzset_run;
  56.     if (! __tzset_run)
  57.       __tzset ();
  58.   }
  59.  
  60.   if (__use_tzfile)
  61.     {
  62.       if (! __tzfile_compute (*timer, &leap_correction, &leap_extra_secs))
  63.     return NULL;
  64.     }
  65.   else
  66.     {
  67.       tp = gmtime (timer);
  68.       if (tp == NULL)
  69.     return NULL;
  70.  
  71.       if (! __tz_compute (*timer, tp))
  72.     return NULL;
  73.  
  74.       leap_correction = 0L;
  75.       leap_extra_secs = 0;
  76.     }
  77.  
  78.   tp = __offtime (timer, __timezone - leap_correction);
  79.   tp->tm_sec += leap_extra_secs;
  80.   tp->tm_isdst = __daylight;
  81.   tp->tm_gmtoff = __timezone;
  82.   tp->tm_zone = __tzname[__daylight];
  83.   return tp;
  84. }
  85.